package com.health.system.dao.system;

import java.util.List;
import java.util.Map;

import cn.org.rapid_framework.page.Page;
import cn.org.rapid_framework.page.PageRequest;
import org.springframework.stereotype.Component;
import com.health.system.javacommon.base.BaseIbatis3Dao;
import com.health.system.model.system.*;

@Component("permissionDao")
public class PermissionDao extends BaseIbatis3Dao<Permission,java.lang.String>{

	public Class getEntityClass() {
		return Permission.class;
	}
	
	public void saveOrUpdate(Permission entity) {
		if(entity.getId() == null) 
			save(entity);
		else 
			update(entity);
	}
	
	public int removeByIdArry(Permission u) {
		int i=-1;
		i =delete("Permission.removeByIdArry", u);
		return i;
	}
	
	public Page findByPageRequest(PageRequest pageRequest) {
		return pageQuery("Permission.pageSelect",pageRequest);
	}
	public Page pageNewSelect(PageRequest pageRequest) {
		return pageQuery("Permission.pageNewSelect", pageRequest);
	}

	/**
	 * @param type
	 *            类型
	 * @return 根据类型取出所有权限名及权限对应资源
	 */
	public List getAllByType(String type) {
		List list = getSqlSessionTemplate().selectList("Permission.selectAll",
				type);
		return list;
	}

	/**
	 * @author pch 2010.6.21
	 * 
	 * @return 所有权限及权限对应的资源
	 */
	public List selectPermissionMenuAndAction() {
		List list = getSqlSessionTemplate().selectList(
				"Permission.selectPermissionMenuAndAction", null);
		return list;
	}

	/**
	 * @param userId
	 *            用户ID
	 * @return 用户拥有的所有权限
	 */
	public List getPermissionByUserId(String userId) {
		List list = getSqlSessionTemplate().selectList(
				"Permission.getPermissionByUserId", userId);
		return list;
	}

	/**
	 * create:pch 2010.6.4 根据权限ID删除角色权限关系表的关联数据项
	 * 
	 * @param permissionId
	 */
	public void deleteRolePermission(String id) {
		delete("Permission.rolePermissionDelete", id);
	}

	/**
	 * 多条件查询数据
	 * 
	 * @author bzq
	 * @param Map
	 */
	public List getListByMap(Map map) {
		return getList("Permission.getListByMap", map);
	}
	
	public List getPermissionByName(String name) {
		return getList("Permission.getPermissionByName", name);
	}
	

}
